var t = getApp(), n = 0;

Page({
    data: {
        topHeight:1,
        notPlusHidden:1
    },
    onLoad: function() {
        wx.setNavigationBarColor({
            frontColor: '#000000',
            backgroundColor: '#E1C28F',
            animation: {
                duration: 400,
                timingFunc: 'easeIn'
            }
        });
    },
    onShow:function(){
        console.log(t.globalData);
        this.setData({
            userName :t.globalData.userInfo.nickName,
            avatar:t.globalData.userInfo.avatarUrl,
        });
        this.user();
    },
    user: function() {
        var e = this, o = wx.getStorageSync("token");
        wx.request({
            url: t.apiUrl("user/info"),
            data: {
            },
            header: {
                "Content-Type": "application/json",
                "X-ECTouch-Authorization": o
            },
            method: "POST",
            success: function(res) {
               if(res.data.data.user_rank == 12){
                   e.setData({
                       notPlusHidden:1,
                       plusTime:res.data.data.plusTime
                   })
               }else{ 
                    e.setData({
                        notPlusHidden:0,
                        plusTime:res.data.data.plusTime
                    })
               }
            }
        });
    },
    buyPlus:function () {
        var that = this;
        var e = this, token = wx.getStorageSync("token");
        wx.request({
            url: t.apiUrl("payment/buyPlus"),
            data: {
                money:0.01,
                open_id:wx.getStorageSync("openid")
            },
            header: {
                "Content-Type": "application/json",
                "X-ECTouch-Authorization": token
            },
            method: "POST",
            success: function(res) {
                if (500 != res.data.status_code) {
                    var i = res.data.data.wxpay;
                    "" != i && wx.requestPayment({
                        timeStamp: i.timestamp,
                        nonceStr: i.nonce_str,
                        package: i.packages,
                        signType: "MD5",
                        paySign: i.sign,
                        success: function (t) {
                            "requestPayment:ok" == t.errMsg && wx.request({
                                url: getApp().apiUrl("payment/payPlusSuccess"),
                                data: {
                                    log_id: res.data.data.log_id
                                },
                                method: "post",
                                header: {
                                    "Content-Type": "application/json",
                                    "X-ECTouch-Authorization": token
                                },
                                success: function (t) {
                                    0 == t.data.data.code ? (wx.showToast({
                                        title: "支付成功",
                                        duration: 2e3
                                    }), that.setData({ 
                                        notPlusHidden:1,
                                        plusTime:(new Date()).getFullYear()+'-'+((new Date()).getMonth()+1)+'-'+(new Date()).getDate()
                                    }) ): wx.showToast({
                                        title: "付款失败",
                                        image: "../../images/failure.png",
                                        duration: 2e3
                                    });
                                }
                            });
                        },
                        fail: function (t) {
                            wx.showToast({
                                title: "支付失败",
                                image: "../../images/failure.png",
                                duration: 2e3
                            })
                        }
                    });
                } else wx.showToast({
                    title: "支付失败",
                    image: "../../images/failure.png",
                    duration: 2e3
                });
            }
        });
    }
});